import request from "../utils/request";

const orderApi = {
  // 获取订单列表
  getOrderList: (userId) => {
    return request.get(`/order-service/order/selectPassengerAllOrderList?userId=${userId}`);
  },
  // 获取未支付订单列表
  toBePaidList: (userId) => {
    return request.get(`/order-service/order/selectCompletedUnpaid?userId=${userId}`); 
  },
  // 获取待出行订单列表 - 修复接口路径
  toBeOutList: (userId) => {
    // 如果待出行接口不存在，可以使用全部订单接口然后过滤
    return request.get(`/order-service/order/selectPassengerWaitingOrderList?userId=${userId}`); 
  },
  // 获取已取消订单列表
  cancelledList: (userId) => {
    return request.get(`/order-service/order/selectPassengerCancelOrderList?userId=${userId}`);
  },
  // 获取已完成订单列表
  completedList: (userId) => {
    return request.get(`/order-service/order/selectCompleteThePayment?userId=${userId}`);  
  },
  // 获取订单详情
  getOrderDetail: (orderId) => {
    return request.get(`/order-service/order/getOrderDetail?orderId=${orderId}`);
  },
  // 取消订单
  cancelOrder: (order) => {
    console.log(order,"-----111---")
    //获取本地存储的用户信息
    const user = uni.getStorageSync('user');
    // 构建订单DTO对象
    const orderDTO = {
      orderId: order.orderNo,
      orderStatus: order.orderStatus,
      orderState: order.orderState,
      passengerId: user.userId,
      price: order.price
    };
    console.log(orderDTO,"-----222---")
    return request.put(`/order-service/order/cancelOrder`, orderDTO);
  },
  //删除订单
  deleteOrder: (orderId) => {
    return request.post(`/order-service/order/deleteOrder?orderId=${orderId}`);
  },
  // 确认收货
  confirmReceipt: (orderId) => {
    return request.post(`/order-service/order/confirmReceipt?orderId=${orderId}`);
  },
  // 支付订单
  payOrder: (orderId) => {
    return request.post(`/order-service/order/payOrder?orderId=${orderId}`);
  },
  // 评价订单
  evaluateOrder: (orderId, evaluation) => {
    return request.post(`/order-service/order/evaluateOrder?orderId=${orderId}`, evaluation);
  },
  // 退款订单
  refundOrder: (orderId, reason) => {
    return request.post(`/order-service/order/refundOrder?orderId=${orderId}`, reason);
  },    
  //结算界面查找订单信息
  getOrderInfo:(orderId) =>{
	return request.get(`/order-service/order/selecetOrderAndDriver?orderId=${orderId}`)
  }
};

export default orderApi;